<template>
  <div class="user-page">
    <!-- <router-view/> -->

    <div class="My_title__39w3V">
      <img
       v-if="!getToken()"
        class="My_bg__2j-VX"
        src="http://liufusong.top:8080/img/profile/bg.png"
        alt="背景图"
      />
        <img
        v-else-if="getToken()"
        class="My_bg__2j-VX"
        src="https://img1.baidu.com/it/u=1459759203,398990576&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500"
        alt="背景图"
      />
      <div class="My_info__eOYeg">
        <div class="My_myIcon__3cKIV">
          <img
            class="My_avatar__2Fbh7"
            src="https://img2.baidu.com/it/u=864800148,863255913&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
            alt="icon"
          />
        </div>
        <div class="user">
          <van-button v-if="!getToken()" type="primary" @click="toLogin"
            >马上登录</van-button
          >
          <van-button
            v-else-if="getToken()"
            icon="https://img01.yzcdn.cn/vant/user-active.png"
            type="primary"
            @click="closeFn"
            >想退出了吗</van-button
          >
        </div>
      </div>
    </div>
    <van-grid class="mt20" :column-num="3">
      <van-grid-item icon="star-o" text="我的收藏" @click="goinFn" />
      <van-grid-item icon="send-gift-o" text="我的出租" @click="goinSell" />
      <van-grid-item icon="service-o" text="看房记录" />
      <van-grid-item icon="notes-o" text="成为房主" />
      <van-grid-item icon="user-circle-o" text="个人资料" />
      <van-grid-item icon="friends-o" text="联系我们" />
    </van-grid>
    <div class="mt200">
      <img class="bgc" src="" alt="" />
    </div>
  </div>
</template>

<script>
import { logout } from '@/api/atticle'

import { getToken, delToken } from '@/utils/storage'
export default {
  name: 'user-page',
  data () {
    return {
      getToken,
      delToken
    }
  },
  async created () {},
  methods: {
    goinSell () {
      if (getToken()) {
        this.$router.push('/sell')
      } else {
        this.$toast.fail('还没登陆呢宝贝')
        this.$router.push('/login')
      }
    },
    goinFn () {
      if (getToken()) {
        this.$router.push('/collect')
      } else {
        this.$toast.fail('还没登陆呢宝贝')
        this.$router.push('/login')
      }
    },

    toLogin () {
      this.$router.push('/login')
    },
    // 退出登录的设置
    async closeFn () {
      await this.$dialog.confirm({
        message: '你这个笨蛋确定要退出了吗',
        beforeClose (action, done) {
          if (action === 'confirm') {
            logout()
            delToken()
            setTimeout(done, 100)
          } else {
            done()
          }
        }
      })
      if (!getToken()) {
        this.$router.push('/')
      }
    }
    // 进入我的收藏如果没有token信息的话直接进入login
  }
}
</script>

<style lang="less" scoped>
.bgc {
  // height: 100px;
  width: 100%;
}
.mt200 {
  margin-top: 20px;
  opacity: 0.8;
}
.mt20 {
  margin-top: 20px;
}
.user {
  position: relative;
  transform: translateY(-50%);
}
.My_myIcon__3cKIV {
  position: relative;
  transform: translateY(-50%);
  border-radius: 50%;
  width: 70px;
  height: 70px;
  border: 5px solid #f5f5f5;
  display: inline-block;
  box-shadow: 0 2px 2px #bdbdbd;
}
.My_avatar__2Fbh7 {
  width: 100%;
  border-radius: 50%;
}
.My_title__39w3V {
  min-height: 300px;
  position: relative;
}
.My_bg__2j-VX {
  width: 100%;
}
.My_info__eOYeg {
  position: absolute;
  background: #fff;
  width: 85%;
  height: 40%;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px 3px #ddd;
  margin: 50px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 13px;
  opacity: 0.7;
}
</style>
